/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Thanh Minh
 */
public class MysqldataAccesshelper {
    private Connection connnection;

    public Connection getConnnection() {
        return connnection;
    }

    public void setConnnection(Connection connnection) {
        this.connnection = connnection;
    }

   
    
    public MysqldataAccesshelper() throws SQLException{
        open();
    }
    public void open() throws SQLException{
        this.connnection=MySQLConnectionUtil.getInstance().getConnection();
    }
    public void close() throws SQLException{
       try{
           this.connnection.close();
       }
       catch(SQLException ex){
           System.out.println(ex.getMessage().toString());
       }
    }
     public ResultSet executeQuery(String sql) {
      ResultSet rs = null;
      try {

         Statement sm =this.connnection.createStatement();
         rs = sm.executeQuery(sql);
      } catch (SQLException ex) {
         System.out.println(ex.getMessage());
      }
      return rs;
   }
      public int executeUpdate(String sql) {
      int num = -1;
      try {
         Statement sm = this.connnection.createStatement();
         num = sm.executeUpdate(sql);
      } catch (SQLException ex) {
        System.out.println(ex.getMessage());
      }
      return num;
   }
}
